package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

import static com.atguigu.gulimall.order.config.GuliMallRabbitConfig.DELAYED_ROUTING_KEY;
import static com.atguigu.gulimall.order.config.GuliMallRabbitConfig.ORDER_EVENT_EXCHANGE;

/**
 * @Author ShiJieLin
 * @Date 2022/4/29 20:02
 * @Version 1.0
 */
@Controller
public class HelloController {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/test/rabbit")
    @ResponseBody
    public String testRabbit() {

        OrderEntity entity = new OrderEntity();
        entity.setCreateTime(new Date());
        entity.setId(1L);
        entity.setOrderSn(UUID.randomUUID().toString());

        rabbitTemplate.convertAndSend(ORDER_EVENT_EXCHANGE, DELAYED_ROUTING_KEY, entity);

        String ok = "ok";
        return ok;
    }



    @GetMapping(value = "/{page}.html")
    public String listPage(@PathVariable("page") String page) {

        return page;
    }

}
